package com.bilibili.juc.cf.one;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@AllArgsConstructor
@NoArgsConstructor
public class FutureResultVO<T> {
    public static final int SUCCESS_CODE = 200;
    public static final int FAIL_CODE = -1;
    private int code;
    private T data;
    private String msg;
    private Throwable ex;
    public boolean isSuccess(){
        return code == SUCCESS_CODE;
    }

    public static <T> FutureResultVO<T> success(T data){
        return new FutureResultVO<>(SUCCESS_CODE,data,"success",null);
    }
    public static <T> FutureResultVO<T> fail(Throwable ex){
        return new FutureResultVO<>(FAIL_CODE,null,"fail",ex);
    }
    public static <T> FutureResultVO<T> fail(String msg,Throwable ex){
        return new FutureResultVO<>(FAIL_CODE,null,msg,ex);
    }

    public static <T> FutureResultVO<T> fail(int code,String msg,Throwable ex){
        return new FutureResultVO<>(code,null,msg,ex);
    }

}
